<?php
/*
 * @author eBIZ Team <dev@jungo.com.cn>
 * @copyright  Copyright (c) , ShenZhen JunGO Technology Co., Ltd. All rights reserved.
 * @license  Commercial authorization, unauthorized use and modification are prohibited
 * @url www.jungo.com.cn
 */

namespace ckeeper\services\impl;


use ckeeper\dao\ManagerRightsDao;
use ckeeper\entity\ManagerRightsEntity;
use ckeeper\services\RightsService;
use Selibra\Di\Annotations\Component;
use Selibra\Di\Annotations\Autowired;


#[Component]
class RightsServiceImpl implements RightsService
{

    /**
     * @var ManagerRightsDao
     */
#[Autowired]
    protected ManagerRightsDao $rightsDao;

    /**
     * 通过路由获取权限信息
     * @param string $route 路由地址
     * @param string $method 请求方法
     * @return ManagerRightsEntity
     */
    public function getRightByRoute(string $route,string $method)
    {
        $this->rightsDao->getCondition()
            ->andWhere('route', '=', $route)
            ->andWhere('method','=',strtoupper($method));
        return $this->rightsDao->get();
    }

    /**
     * @param int $pid
     * @return ManagerRightsEntity[]
     */
    public function getRightsByPid(int $pid = 0)
    {
        $this->rightsDao->getCondition()->andWhere('pid', '=', $pid);
        return $this->rightsDao->select();
    }
}
